#include <stdio.h>
#include <netinet/in.h>


/* Looking for private ips */
#define PRIVATE_IN_CLASSC(a)            ((((in_addr_t)(a)) & 0xFFFF0000) == 0xc0a80000)
#define PRIVATE_IN_CLASSB(a)            ((((in_addr_t)(a)) & 0xFFF00000) == 0xac100000)
#define PRIVATE_IN_CLASSA(a)            ((((in_addr_t)(a)) & 0xFF000000) == 0x0a000000)

/*
 * Return !=0 if the ip is private.
 */
inline int is_private(struct in_addr *address)
{
	u_int32_t ip;
	ip = ntohl(address->s_addr);

	if (PRIVATE_IN_CLASSC(ip)){
		printf("Ip privada. (C)\n");
		return 1;
	}
	if (PRIVATE_IN_CLASSA(ip)){
		printf("Ip privada. (A)\n");
		return 1;
	}
	if (PRIVATE_IN_CLASSB(ip)){
		printf("Ip privada. (B)\n");
		return 1;
	}
	return 0;
}


int main(int argc, char **argv)
{

	struct in_addr ip;

	inet_aton(argv[1],&ip);

	if (is_private(&ip)!=0) printf ("La ip %s es privada\n",inet_ntoa(ip));
	else printf("NO es privada\n");


	//printf("Ip: %s\n",inet_ntoa(ip));
	
	return 0;


}
